package tech.aistar.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import tech.aistar.entity.dynamic.ImgsStorage;
import tech.aistar.entity.trading.Goods;
import tech.aistar.entity.trading.GoodsDetails;
import tech.aistar.entity.trading.GoodsType;
import tech.aistar.entity.trading.Report;
import tech.aistar.mapper.CollectionsMapper;
import tech.aistar.mapper.ImgsStorageMapper;
import tech.aistar.mapper.trading.GoodsDetailsMapper;
import tech.aistar.mapper.trading.GoodsMapper;
import tech.aistar.mapper.trading.ReportMapper;
import tech.aistar.service.IGoodsService;

import java.util.List;

/**
 * @author Ace
 * @version 1.0
 * @descriiption:本类用来演示:
 * @date 2019/9/28 0028.
 */
@Service
public class GoodsServiceImpl implements IGoodsService{
    @Autowired
    private GoodsMapper goodsMapper;
    @Autowired
    private GoodsDetailsMapper goodsDetailsMapper;
    @Autowired
    private ReportMapper reportMapper;
    @Autowired
    private CollectionsMapper collectionsMapper;
    @Autowired
    private ImgsStorageMapper imgsStorageMapper;
    /**
     * 添加商品
     */
    @Override
    public void save(Goods goods) {
        goodsMapper.save(goods);
    }
    /**
     * 删----通过设置status的值达到删除某个数据,不用真的删除
     * @param id
     */
    @Override
    public void delById(Integer id) {
            goodsMapper.delById(id);
    }
    /**
     * 查----查所有
     */
    @Override
    public List<Goods> findAll1() {
        return goodsMapper.findAll();
    }
    /**
     * 查--根据id查
     */
    @Override
    public Goods findById(Integer id) {

        return goodsMapper.findById(id);
    }



    /**
     * 类型+商品简介
     * 如果条件不存在,则查询所有的
     * 多条件组合查询...一句写不完,所以弄个PhoneMapper.xml
     * 进行模糊查询
     */
    @Override
    public List<Goods> findAllLike(String goodsName, Integer goodsTypeId) {
        List<Goods> goodsList=goodsMapper.findAllLike(goodsName,goodsTypeId);
        return goodsList;
    }
    /**
     * 改--修改商品信息
     */
    @Override
    public void Update(Goods goods) {
                goodsMapper.Update(goods);
    }
    /**
     *多条件组合+分页查询
     * @param pageNum  当前页
     * @param pageSize  每页显示条数
     * @return
     */
    @Override
    public PageInfo<Goods> findAll2(String goodsName, Integer goodsTypeId, Integer pageNum, Integer pageSize) {
        PageHelper.startPage(pageNum,pageSize);
        List<Goods> goodsList=goodsMapper.findAllLike(goodsName,goodsTypeId);
        PageInfo<Goods> pageInfo=new PageInfo<>(goodsList);
        return pageInfo;
    }

    @Override
    public GoodsDetails findBygoodsId(Integer goodsId) {
        GoodsDetails goodsDetails=goodsDetailsMapper.findById(goodsId);
        return goodsDetails;
    }

    @Override
    public void updateReport(Report report) {
        reportMapper.updateReport(report);
    }

    @Override
    public Report findReportByuId(String uId) {
        Report report=reportMapper.findReportByuId(uId);
        return report;
    }

    @Override
    public void addGoods(Integer id, Integer kindId) {
        collectionsMapper.addGoods(id,kindId);
    }

    @Override
    public List<ImgsStorage> fingimgByGoodsId(Integer goodsId) {
       List<ImgsStorage> list=imgsStorageMapper.findByGoodsId(goodsId);
        return list;
    }


}
